//
//  EFShareView.m
//  EnjogFood
//
//  Created by guocheng on 2017/6/11.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFShareView.h"
#import <UMSocialCore/UMSocialCore.h>
#import "EFShareStyleViewController.h"

@interface EFShareView ()

@property(nonatomic, strong)UIView *shareLayerView;
@property(nonatomic, strong)UIView *bgView;
@property(nonatomic, strong)UIButton *cancelBtn;


@property(nonatomic, strong)EFShareInfo *info;
@property(nonatomic, strong)NSString *goodsId;
@property(nonatomic, strong) UIImage *shareImage;

@end

@implementation EFShareView

-(instancetype)initWithGoodsId:(NSString *)goodsId{
    self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    if (self) {
        self.shareLayerView.alpha = 0.2f;
        self.bgView.bottom = kScreenHeight;
        self.goodsId = goodsId;
        [self initView];
    }
    return self;
}

- (void)initView{
    [self addSubview:self.shareLayerView];
    self.bgView.bottom = kScreenHeight;
    [self addSubview:self.bgView];
    NSArray *names = @[ @"微信",@"朋友圈",@"微博"];
    NSArray *imgs  = @[ @"share_icon_wechat",@"share_icon_circle",@"share_icon_sina"];
    CGFloat space = (kScreenWidth - 4*50)/5.f;
    for (int i = 0; i < names.count; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(space + (50 + space) * i, 25.f, 50.f, 60.f)];
        [button setImage:IMG(imgs[i]) forState:UIControlStateNormal];
        [button setImageEdgeInsets:UIEdgeInsetsMake(-10, 5.f, 0, 0)];
        [button setTitle:names[i] forState:UIControlStateNormal];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(50, -40.f, 0, 0)];
        [button setTitleColor:kBlack666 forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:11.f];
        button.tag = 10000 + i;
        [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:button];
    }
    self.cancelBtn.bottom = self.bgView.height;
    [self.bgView addSubview:self.cancelBtn];
} 

-(void)onClickCancelBtn{
    [self removeFromSuperview];
}


- (UIView *)shareLayerView{
    if (!_shareLayerView) {
        _shareLayerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _shareLayerView.backgroundColor = [UIColor blackColor];
        _shareLayerView.alpha = 0.5f;
    }
    return _shareLayerView;
}

- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 160.f)];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 45.f)];
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:kBlack666 forState:UIControlStateNormal];
        _cancelBtn.backgroundColor = RGBCOLOR(0x69BA45);
        [_cancelBtn addTarget:self action:@selector(onClickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}


#pragma mark ----- button method -----
- (void)doButton:(id)sender{
    [self onClickCancelBtn];
     UIButton *b  = (UIButton *)sender;
    EShareType type = EShareTypeWx;
    switch (b.tag % 10000)
    {
            case 0:
            {
                type = EShareTypeWx;
                break;
            }
            case 1:
            {
                type = EShareTypeCircle;
                break;
            }
            case 2:
            {
                type = EShareTypeWb;
                break;
            }
    }
    
    EFShareStyleViewController* shareStyle = [[EFShareStyleViewController alloc]initWithProductId:self.goodsId type:type];
    [ICNavigator pushViewController:shareStyle animated:YES];
}

@end
